//
//  AnimationView.swift
//  SwiftUIAnimation
//
//  Created by 李煜 on 2024/8/19.
//

import SwiftUI
//隐式动画 .animation
struct AnimationView: View {
  @State private var circleColorChange = false
  @State private var heartColorChange = false
  @State private var heartSizeChange = false
  var body: some View {
    // 方式一:animation单独写在各个控件上
    Text("每个子控件单独使用animation").font(.title)
    ZStack {
      Circle()
        .frame(width: 200, height: 200)
        .foregroundStyle(circleColorChange ? Color(.systemGray5) : .cyan)

        .animation(.default, value: circleColorChange)

      Image(systemName: "heart.fill")
        .foregroundStyle(heartColorChange ? .cyan : .white)
        .font(.system(size: 100))
        .scaleEffect(heartSizeChange ? 1.0 : 0.5)

        .animation(.default, value: heartSizeChange)
    }
    .onTapGesture {
      circleColorChange.toggle()
      heartSizeChange.toggle()
      heartColorChange.toggle()
    }
  }
}

#Preview {
  AnimationView()
}
